﻿using Playnite.Common;
using Playnite.SDK.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ImportExporter
{
    public static class Utils
    {
        public static void WriteJsonFile(String filePath, object obj)
        {
            //var filePath = Path.Combine(path, @"LocalGameMetadata.json");
            FileSystem.PrepareSaveFile(filePath);
            File.WriteAllText(filePath, Serialization.ToJson(obj));
        }

        public static void CopyDirectory(string sourceDir, string destinationDir)
        {
            // 创建目标目录，如果它不存在
            if (!Directory.Exists(destinationDir))
            {
                Directory.CreateDirectory(destinationDir);
            }

            // 获取源目录中的所有文件并复制它们
            foreach (string file in Directory.GetFiles(sourceDir))
            {
                string destFile = Path.Combine(destinationDir, Path.GetFileName(file));
                File.Copy(file, destFile, true); // true 允许覆盖现有的文件
            }

            // 获取源目录中的所有子目录并递归复制它们
            foreach (string directory in Directory.GetDirectories(sourceDir))
            {
                string destDirectory = Path.Combine(destinationDir, Path.GetFileName(directory));
                CopyDirectory(directory, destDirectory);
            }
        }
    }
}
